<html>
<head>
<style>
  .ace_editor {
    border: 0;
    width: auto;
    height: 100%;
    margin: 0;
    top:0;
    right:0;
    bottom:0;
    left:0;
    z-index: 10000;
    touch-action: none;
  }

  body {
    padding: 0px;
    margin: 0px;
    overflow: hidden;
    -ms-overflow-style: scrollbar;
  }
</style>
</head>
<body>
<textarea id="source">package com.sencha.gxt.explorer.client.animation;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Style.Overflow;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;
import com.sencha.gxt.core.client.Style.Direction;
import com.sencha.gxt.core.client.util.Rectangle;
import com.sencha.gxt.explorer.client.app.ui.ExampleContainer;
import com.sencha.gxt.explorer.client.model.Example.Detail;
import com.sencha.gxt.fx.client.FxElement;
import com.sencha.gxt.fx.client.animation.AfterAnimateEvent;
import com.sencha.gxt.fx.client.animation.AfterAnimateEvent.AfterAnimateHandler;
import com.sencha.gxt.fx.client.animation.Fx;
import com.sencha.gxt.widget.core.client.ContentPanel;
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
import com.sencha.gxt.widget.core.client.button.ButtonBar;
import com.sencha.gxt.widget.core.client.button.TextButton;
import com.sencha.gxt.widget.core.client.container.FlowLayoutContainer;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;

public class AnimationExample implements IsWidget, EntryPoint {

  protected static final int PREFERRED_HEIGHT = 320;
  protected static final int PREFERRED_WIDTH = 435;

  private ContentPanel cp;
  private FlowLayoutContainer panel;
  private ArrayList<TextButton> toggleableButtons;
  private Fx fx = new Fx();

  @Override
  public Widget asWidget() {
    if (panel == null) {
      TextButton slide = new TextButton("Slide In / Out");
      slide.addSelectHandler(new SelectHandler() {
        @Override
        public void onSelect(SelectEvent event) {
          slideFx(event);
        }
      });

      TextButton fade = new TextButton("Fade In / Out");
      fade.addSelectHandler(new SelectHandler() {
        @Override
        public void onSelect(SelectEvent event) {
          fadeFx();
        }
      });

      TextButton move = new TextButton("Move");
      move.addSelectHandler(new SelectHandler() {
        @Override
        public void onSelect(SelectEvent event) {
          moveFx();
        }
      });

      TextButton blink = new TextButton("Blink");
      blink.addSelectHandler(new SelectHandler() {
        @Override
        public void onSelect(SelectEvent event) {
          blinkFx();
        }
      });

      TextButton event = new TextButton("Event");
      event.addSelectHandler(new SelectHandler() {
        @Override
        public void onSelect(SelectEvent event) {
          eventFx();
        }
      });

      TextButton reset = new TextButton("Reset");
      reset.addSelectHandler(new SelectHandler() {
        @Override
        public void onSelect(SelectEvent ev) {
          resetFx();
        }
      });

      ButtonBar buttonBar = new ButtonBar();
      buttonBar.add(slide);
      buttonBar.add(fade);
      buttonBar.add(move);
      buttonBar.add(blink);
      buttonBar.add(event);
      buttonBar.add(reset);

      cp = new ContentPanel();
      cp.setHeading("Animation");
      cp.setPixelSize(200, 200);
      cp.setPosition(115, 70);

      panel = new FlowLayoutContainer();
      panel.getElement().getStyle().setOverflow(Overflow.VISIBLE);
      panel.add(buttonBar);
      panel.add(cp);

      toggleableButtons = new ArrayList<TextButton>();
      toggleableButtons.add(move);
      toggleableButtons.add(blink);
      toggleableButtons.add(event);
    }

    return panel;
  }

  private void slideFx(SelectEvent event) {
    if (cp.isVisible()) {
      setEnabled(toggleableButtons, false);
      cp.getElement().<FxElement> cast().slideOut(Direction.UP, fx);
    } else {
      setEnabled(toggleableButtons, true);
      cp.getElement().<FxElement> cast().slideIn(Direction.DOWN, fx);
    }
  }

  private void fadeFx() {
    setEnabled(toggleableButtons, !cp.getElement().isVisible());
    cp.getElement().<FxElement> cast().fadeToggle(fx);
  }

  private void moveFx() {
    Rectangle bounds = cp.getElement().getBounds();
    cp.getElement().<FxElement> cast().setXY(bounds.getX() + 50, bounds.getY() + 50, fx);
  }

  private void blinkFx() {
    cp.getElement().<FxElement> cast().blink(fx, 50);
  }

  private void eventFx() {
    Fx fx = new Fx();
    fx.addAfterAnimateHandler(new AfterAnimateHandler() {
      @Override
      public void onAfterAnimate(AfterAnimateEvent event) {
        AlertMessageBox mb = new AlertMessageBox("Animate Event Handler", "AfterAnimateEvent was received...");
        mb.setIcon(AlertMessageBox.ICONS.info());
        mb.show();
      }
    });
    cp.getElement().<FxElement> cast().blink(fx, 50);
  }

  private void resetFx() {
    setEnabled(toggleableButtons, true);

    cp.setPosition(115, 70);
    cp.getElement().show();
    cp.expand();
  }

  @Override
  public void onModuleLoad() {
    new ExampleContainer(this)
        .setPreferredHeight(PREFERRED_HEIGHT)
        .setPreferredWidth(PREFERRED_WIDTH)
        .doStandalone();
  }

  private void setEnabled(List<TextButton> buttons, boolean enabled) {
    for (TextButton button : buttons) {
      button.setEnabled(enabled);
    }
  }

}
</textarea>

<script src="../../samples/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
  var type = "{type}";
  if (type == ("{" + "type}")) {
    // something went wrong, use java as default
    type = "java";
  }
  var editor = ace.edit("source");
  var mode = "ace/mode/" + type;
  var theme = "ace/theme/chrome";
  var readOnly = true;
  editor.getSession().setMode(mode);
  editor.getSession().setUseWorker(false);
  editor.setTheme(theme);
  editor.setShowPrintMargin(false);
  editor.renderer.setShowGutter(true);
  editor.setHighlightActiveLine(false);
  editor.setDisplayIndentGuides(true);
  editor.setReadOnly(readOnly);
  editor.renderer.setPadding(10);
  editor.renderer.setScrollMargin(10, 10, 0, 0);
  editor.getSession().setOptions({
    tabSize: 8,
    useSoftTabs: true,
    useWrapMode: false,
  });
</script>
</body>
</html>